local skel = fk.CreateSkill {
  name = "lb_zero__chiyi",
}

Fk:loadTranslationTable {
  ["lb_zero__chiyi"] = "赤义",
  [":lb_zero__chiyi"] = "每回合限一次，当体力值或手牌数最少的角色受到伤害时，你可对伤害来源使用一张无距离限制的伤害牌，若造成伤害，则令其本次造成的伤害-X（X为此牌因<a href=':lb_zero__zhuixuan'><font color='red'>〖锥旋〗</font></a>增加的伤害值+1）。",

  ["#lb_zero__chiyi"] = "赤义：%src 即将受到 %arg点%arg2伤害，你可以对 %dest 使用一张无距离限制的伤害牌，若造成伤害，可减少%src受到的伤害",

  ["$lb_zero__chiyi1"] = "哈哈！",
  ["$lb_zero__chiyi2"] = "兄弟，我们一起！",
}

skel:addEffect(fk.DamageInflicted, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and target and data.from
        and player:usedSkillTimes(skel.name) == 0
        and (not table.find(player.room:getAlivePlayers(), function(to)
          return to.hp < target.hp
        end) or not table.find(player.room:getAlivePlayers(), function(to)
          return to:getHandcardNum() < target:getHandcardNum()
        end))
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local list = {}
    for name, card in pairs(Fk.all_card_types) do
      if card.is_damage_card then
        table.insert(list, name)
      end
    end
    if #list == 0 then return end
    local use = room:askToUseCard(player, {
      pattern = table.concat(list, ","),
      skill_name = skel.name,
      prompt = "#lb_zero__chiyi:" .. target.id .. ":" .. data.from.id .. ":" .. data.damage .. ":" .. Fk:getDamageNatureName(data.damageType),
      cancelable = true,
      extra_data = { bypass_distances = true, must_targets = { data.from.id } }
    })
    if use then
      event:setCostData(self, { use = use })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local use = event:getCostData(self).use ---@type UseCardDataSpec
    room:useCard(use)
    if use.damageDealt then
      local num = 1
      if use.extra_data and use.extra_data.lb_zero__zhuixuan then
        num = num + use.extra_data.lb_zero__zhuixuan
      end
      data.damage = data.damage - num
      if data.damage < 1 then
        data:preventDamage()
      end
    end
  end,
})


return skel
